# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import wx                        # This module uses the new wx namespace
import images

_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

#---------------------------------------------------------------------------

class My_ExitDialog(wx.Dialog):
    def __init__(self, parent, title, pos=wx.DefaultPosition,
                 size=wx.DefaultSize):

        self.ReturnValue = False

        wx.Dialog.__init__(self, parent, -1, title, pos, size,
                           style=wx.DEFAULT_DIALOG_STYLE & ~wx.CLOSE_BOX)
        
        #-------------------------------------------------------------------
        
        self.parent = parent
    
        #-------------------------------------------------------------------

        # Simplified init method
        self.createWidget()
        self.doLayout()

        #-------------------------------------------------------------------
        
        self.Centre()
        
        #-------------------------------------------------------------------
        
        self.ReturnValue = not self.ShowModal()
        self.Destroy()

    #-----------------------------------------------------------------------
        
    def createWidget(self):
        fontSize = self.GetFont().GetPointSize()
         
        # wx.Font(pointSize, family, style, weight, underline, faceName) 
        if wx.Platform == "__WXMAC__":
            self.btnFont = wx.Font(fontSize-1,
                                   wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
            self.boldFont = wx.Font(fontSize+2,
                                    wx.DEFAULT, wx.NORMAL, wx.BOLD, False, "")
              
        elif wx.Platform == "__WXGTK__":
            self.btnFont = wx.Font(fontSize,
                                   wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
            self.boldFont = wx.Font(fontSize,
                                    wx.DEFAULT, wx.NORMAL, wx.BOLD, False, "")
              
        else:
            self.btnFont = wx.Font(fontSize,
                                   wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, "")
            self.boldFont = wx.Font(fontSize,
                                    wx.DEFAULT, wx.NORMAL, wx.BOLD, False, "")
              
        self.SetFont(self.btnFont)
        self.SetFont(self.boldFont)
         
        #-------------------------------------------------------------------
        
        self.panel1 = wx.Panel(self, -1)
        self.panel1.SetBackgroundColour("WHITE")

        #-------------------------------------------------------------------

        bmp = images.Logo_Information.GetBitmap()
        self.logo = wx.StaticBitmap(self.panel1, -1)
        self.logo.SetBitmap(bmp)
        
        #-------------------------------------------------------------------
        
        self.warning = wx.StaticText(self.panel1, -1,
                                     label=_(u"\nVoulez-vous vraiment quitter l'application ?"),
                                     style=wx.ALIGN_CENTRE)
        self.warning.SetFont(self.boldFont)
        self.warning.SetSize(self.warning.GetBestSize())
        self.warning.SetForegroundColour("#4f4f4f")
        
        #-------------------------------------------------------------------
        
        self.btnYES = wx.Button(self, id=wx.ID_YES, label=_(u"&Oui"))
        self.btnYES.SetFont(self.btnFont)
        self.btnYES.SetSize(self.btnYES.GetBestSize())

        # Bind a button event to an event handler
#        self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.btnYES)
        
        self.btnNO = wx.Button(self, id=wx.ID_NO, label=_(u"&Non"))
        self.btnNO.SetFont(self.btnFont)
        self.btnNO.SetSize(self.btnNO.GetBestSize())

        # Bind a button event to an event handler
#        self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.btnNO)
        
        self.btnYES.SetDefault()
        self.btnNO.SetFocus()
        
    #-----------------------------------------------------------------------        

    def doLayout(self):        
        vbox1 = wx.BoxSizer(wx.VERTICAL)     
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        vbox2 = wx.BoxSizer(wx.VERTICAL) 
        btnSizerH1 = wx.BoxSizer(wx.HORIZONTAL)
        btnSizerH2 = wx.BoxSizer(wx.HORIZONTAL)
        fullSizer = wx.BoxSizer(wx.VERTICAL)
        
        #----------
        
        vbox1.Add(self.logo, 0, wx.ALL, 10)        
        hbox1.Add(vbox1, 0, wx.ALIGN_CENTRE, 0)
        hbox1.Add(self.warning, 1, wx.ALIGN_CENTRE | wx.EXPAND | wx.ALL, 15)
        vbox2.Add(hbox1, 1, wx.ALIGN_CENTRE | wx.EXPAND | wx.ALL, 10)
        btnSizerH1.Add(self.btnYES, 0, wx.ALL , 10)
        btnSizerH1.Add(self.btnNO, 1, wx.TOP | wx.BOTTOM | wx.RIGHT, 10) 
        btnSizerH2.Add(btnSizerH1, 1, wx.ALL  | wx.ALIGN_RIGHT, 0)

        #----------
        
        fullSizer = wx.BoxSizer(wx.VERTICAL)
        fullSizer.Add(self.panel1, 0, wx.ALL | wx.EXPAND, 0)
        fullSizer.Add(btnSizerH2,  1, wx.ALL  | wx.ALIGN_RIGHT, 0)
        
        #----------

        self.panel1.SetAutoLayout(True)
        self.panel1.SetSizer(vbox2)
        vbox2.Fit(self)
     
        #----------
        
        self.SetAutoLayout(True)
        self.SetSizer(fullSizer)
        fullSizer.Fit(self)
        
    #-----------------------------------------------------------------------
     
    def IsOK(self):
        return self.ReturnValue


    def OnCloseWindow(self, event):
        self.Destroy()

        
